package com.reading.controller;

import com.github.pagehelper.PageInfo;
import com.reading.pojo.web.Classification;
import com.reading.pojo.web.Tagclass;
import com.reading.service.TagclassService;
import com.reading.vo.Rmed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tagclass")
public class TagclassController {
    @Autowired
    private TagclassService tagclassService;
    //查询标签
    @RequestMapping("/findtag")
    public List<Tagclass> findTag(@RequestBody Tagclass tagclass){
        return tagclassService.findTag(tagclass);
    }
    //添加
    @RequestMapping("/add")
    public Rmed add(@RequestBody Tagclass tagclass){
        try {
            if (tagclass.getId()==null){
                tagclassService.add(tagclass);
            }else{
                tagclassService.update(tagclass);
            }
            return Rmed.suceessData("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("添加失败");
    }
    //删除
    @RequestMapping("/delete")
    public Rmed delete(Integer id){
        try {
            tagclassService.delete(id);
            return Rmed.suceessData("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("删除失败");
    }
}
